﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autofac;
using Bizbase.Services.Security;
using Bizbase.Repository.Nhibernate;
using Bizbase.Repository;

namespace Bizbase.DependencyInjection
{
    public static class Ioc
    {
        public static IContainer Container { get; private set; }

        public static void Run()
        {
            var IocBuilder = new ContainerBuilder();

            //repository register
            IocBuilder.RegisterType<Database>().As<IDatabase>().SingleInstance();
            IocBuilder.RegisterGeneric(typeof(Repository.DataRepository<>)).As(typeof(Repository.IRepository<>)).SingleInstance();

            //sqlQuery register
            IocBuilder.RegisterType<SqlQuery>().As<ISqlQuery>().SingleInstance();

            //services register
            IocBuilder.RegisterType<DefaultSecurityManager>().As<ISecurityManager>().SingleInstance();

            Container = IocBuilder.Build();
        }

        public static void Stop()
        {
            if (Container != null)
                Container.Dispose();
        }
    }
}
